package com.somsoft.handjc.activity.query.xzsp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.somsoft.handjc.activity.LoginActivity;
import com.somsoft.handjc.activity.MainActivity;
import com.somsoft.handjc.activity.R;
import com.somsoft.handjc.activity.query.xzzf.XzzfZhongHeQueryDetailActivity;
import com.somsoft.handjc.activity.setting.SetIpActivity;
import com.somsoft.handjc.util.BaseActivity;
import com.somsoft.handjc.util.MyApplication;
import com.somsoft.handjc.util.Utils;
import com.somsoft.handjc.util.XunChaDataUtil;
import com.somsoft.handjc.util.XzspDataUtil;
import com.somsoft.handjc.util.XzzfDataUtil;
import com.somsoft.handjc.xuncha.po.BusinessInfo;
import com.somsoft.handjc.xzzf.po.CaseInfo;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.TextView;
/**
 * 行政审批  详细页面  业务办理信息
 * 
 * @author Administrator
 * 
 */

@SuppressWarnings("all")
public class XzspDetailBusinessInfoActivity extends BaseActivity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		Intent it = getIntent();
		String itemValue = it.getStringExtra("itemValue");
		String ywlsh = it.getStringExtra("ywlsh");
		
		setTitle("行政审批--业务明细--"+itemValue+"信息");
		setContentView(R.layout.common_detail);
		try {
			getData(ywlsh,itemValue);
		} catch (Exception e) {
			Toast.makeText(XzspDetailBusinessInfoActivity.this, "加载数据失败！", Toast.LENGTH_SHORT).show();
		}
		Utils.closeLoading();
	}
	
	private void getData(String ywlsh,String itemValue) throws Exception{
		try {
			String txt = "";
			if("受理".equals(itemValue)){
				txt = getShouli(ywlsh);
			}else if("承办".equals(itemValue)){//  spbzh(1:承办；2:审核；3:批准)
				txt = getShengPiGuoCheng(ywlsh, "1");
			}else if("审核".equals(itemValue)){
				txt = getShengPiGuoCheng(ywlsh, "2");
			}else if("批准".equals(itemValue)){
				txt = getShengPiGuoCheng(ywlsh, "3");
			}else if("办结".equals(itemValue) || "退回办结".equals(itemValue)){
				txt = getBanjie(ywlsh);
			}else if("特别程序申请".equals(itemValue)){
				txt = getTeBieChengXuShengQing(ywlsh);
			}else if("特别程序结果".equals(itemValue)){
				//程序中无数据   暂时没做
			}
			((TextView)findViewById(R.id.commonDetail)).setText(txt);
		} catch (Exception e) {
			throw e;
		}
	}
	//受理
	private String getShouli(String ywlsh) throws Exception{
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("ywlsh",ywlsh));
		String txt = "";
		try {
			JSONObject obj = XzspDataUtil.detailShouli(params);
			txt += "项目名称：" + obj.getString("XMMC") + "\n";
			txt += "受理时间：" + obj.getString("SLSJ") + "\n";
			txt += "规定办理时限：" + obj.getString("GDBLSX") + "个工作日\n";
			txt += "规定收费：" + obj.getString("GDSF") + "\n";
			txt += "回执编号：" + obj.getString("HZBH") + "\n";
			txt += "受理与否：" + obj.getString("SLYF") + "\n";
			txt += "不受理原因：" + obj.getString("BSLYY") + "\n";
			txt += "单位申请人姓名：" + obj.getString("SQDWHSQRXM") + "\n";
			txt += "经办人姓名：" + obj.getString("SQDWJBRXM") + "\n";
			txt += "联系电话：" + obj.getString("SQDWLXDH") + "\n";
			txt += "受理机关名称：" + obj.getString("SLJGMC") + "\n";
			txt += "组织机构代码：" + obj.getString("SLJGZZJGDM") + "\n";
			txt += "受理单位承办人姓名：" + obj.getString("SLDWCBRXM") + "\n";
			txt += "受理单位承办人工号：" + obj.getString("SLDWCBRGH") + "\n";
			if(obj.getString("SLZLQD").startsWith("\n")){
				txt += "受理资料清单：" + obj.getString("SLZLQD");
			}else{
				txt += "受理资料清单：\n" + obj.getString("SLZLQD");
			}
		} catch (Exception e) {
			throw e;
		}
		return txt;
	}
	//审批过程      spbzh(1:承办；2:审核；3:批准)
	private String getShengPiGuoCheng(String ywlsh,String spbzh) throws Exception{
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("ywlsh",ywlsh));
		params.add(new BasicNameValuePair("spbzh",spbzh));
		String txt = "";
		try {
			JSONObject obj = XzspDataUtil.detailShenpiGuocheng(params);
			txt += "审批环节：" + obj.getString("SPHJMC") + "\n";
			txt += "审批时间：" + obj.getString("SPSJ") + "\n";
			txt += "审批人姓名：" + obj.getString("SPRXM") + "\n";
			txt += "审批人职务：" + obj.getString("SPRZWMC") + "\n";
			txt += "审批意见：" + obj.getString("SPYJ");
		} catch (Exception e) {
			throw e;
		}
		return txt;
	}
	//办结
	private String getBanjie(String ywlsh) throws Exception{
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("ywlsh",ywlsh));
		String txt = "";
		try {
			JSONObject obj = XzspDataUtil.detailBanjie(params);
			txt += "机构名称：" + obj.getString("BJJGMC") + "\n";
			txt += "组织机构代码：" + obj.getString("BJJGZZJGDM") + "\n";
			txt += "办结结果：" + obj.getString("BJJG") + "\n";
			txt += "办结时间：" + obj.getString("BJSJ") + "\n";
			txt += "办结结果描述：" + obj.getString("BLJGMS") + "\n";
			txt += "收费金额：" + obj.getString("SFJE") + "元\n";
			txt += "证件名称：" + obj.getString("ZJMC") + "\n";
			txt += "证件编号：" + obj.getString("ZJBH") + "\n";
			txt += "证件有效期：" + obj.getString("ZJYXQX") + "\n";
			txt += "发证盖章单位：" + obj.getString("FZDW") + "\n";
			txt += "作废或退回原因：" + obj.getString("ZFTHYY");
		} catch (Exception e) {
			throw e;
		}
		return txt;
	}
	//特别程序申请
	private String getTeBieChengXuShengQing(String ywlsh) throws Exception{
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("ywlsh",ywlsh));
		String txt = "";
		try {
			JSONObject obj = XzspDataUtil.detailTbcx(params);
			txt += "特别程序种类：" + obj.getString("TBCXZLMC") + "\n";
			txt += "开始日期：" + obj.getString("TBCXKSRQ") + "\n";
			txt += "特别程序时限：" + obj.getString("TBCXSX") + "\n";
			txt += "批准人：" + obj.getString("TBCXPZR") + "\n";
			txt += "批准人电话：" + obj.getString("TBCXPZRDH") + "\n";
			txt += "批准人手机：" + obj.getString("TBCXPZRSJ") + "\n";
			txt += "启动理由或依据：" + obj.getString("TBCXQDLYHYJ") + "\n";
			txt += "申请内容：" + obj.getString("SQNR");
		} catch (Exception e) {
			throw e;
		}
		return txt;
	}
}











